<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录界面</title>
</head>
<style>
    * {
        padding: 0;
        margin: 0;
    }

    .container {
        width: 100%;
        height: 700px;
        background: url('../lib/img/微信图片_20211014154705.png') no-repeat;
        overflow: hidden;
    }

    .container form {
        width: 450px;
        height: 400px;
        margin: 100px 350px;
        border-radius: 34px;
        background-color: rgba(221, 14, 76, 0.089);

    }

    h3 {
        font-size: 28px;
        text-align: center;
        line-height: 50px;
        margin-bottom: 50px;
    }

    .container .a {
        width: 350px;
        height: 100px;
        margin-top: 30px;
        margin: auto;
        font-size: x-large;
        line-height: 50px;
    }

    input {
        height: 30px;
        width: 250px;
    }

    button {
        font-size: x-large;
        width: 150px;
        margin-left: 100px;
    }

    p {
        color: red;
        font-size: 16px;
        margin-left: 90px;
        display: none;
    }
</style>

<body>
    <div class="container">
        <form>
            <h3>登录界面</h3>
            <a href="../pages/regies.html">没有账户先注册叭</a>
            <div class="a">用户名: <input type="text" name="username">
                <p>*用户名输入不正确</p>
            </div>
            <div class="a">密&nbsp&nbsp&nbsp码: <input type="text" name="password">
                <p>*密码输入不正确</p>
            </div>
            <div class="a"><button type="button">登录</button></div>
        </form>
    </div>
    <script src="../js/jquery-3.6.0.min.js"></script>
    <script>
        let userlist = JSON.parse(localStorage.getItem('userlist'))
        console.log(userlist)
        let btn = document.querySelector('button')
        let usernameV = document.querySelector('input[name="username"]')
        let passwordV = document.querySelector('input[name="password"]')
        btn.onclick = function () {
            let username = usernameV.value
            let password = passwordV.value
            let arr = [{ userN: username, passW: password }]
            console.log('arr', arr)
            if (username == '' || password == '') {
                alert('请输入用户名和密码')
            }
            else {
                let a = userlist.some(item => { return item.userN == username })
                if (a == true) {
                    alert('登录成功')
                    location.href = '../pages/index.html'
                } else {
                    alert('用户名或密码不正确')
                }


            }
        }
        //焦点验证
        $('input[name="username"]').blur(function () {
            if ($('input[name="username"]').val() == "") {
                $('input[name="username"]').next().css({ display: "block" });
            } else {
                $('input[name="username"]').next().css({ display: "none" });
            }
        });
        $('input[name="password"]').blur(function () {
            if ($('input[name="password"]').val() == "") {
                $('input[name="password"]').next().css({ display: "block" });
            } else {
                $('input[name="password"]').next().css({ display: "none" });
            }
        });

    </script>
</body>

</html>